<?php
class lrxml
{

	public static function _curl($url ) {  
	$ch = curl_init();
	
	curl_setopt($ch, CURLOPT_URL, $url); 
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);  
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
	curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/6.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.7) Gecko/20050414 Firefox/1.0.3"); 
	
	curl_setopt($ch,CURLOPT_TIMEOUT,200); 
	
	
	curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
	$result=curl_exec ($ch); 
	curl_close ($ch); 
	return $result; 
	}

	public static function getStrLR($string,$start,$end)
	{
		$str = explode($start,$string);
		$str1 = explode($end,$str[1]);
		return $str1[0];
	}

	public static function searchistory($batch){
	
	$year=gmdate("Y");
	$month=gmdate("m");
	$day=gmdate("d");
	
	$hour=gmdate("H");
	$data=":".$year.$month.$day.":".$hour;
	
	$hash=hash("SHA256",$data);
	
	$xml='<HistoryRequest id="123456">
  <Auth> 
    <ApiName></ApiName>
    <Token>'.$hash.'</Token>
  </Auth>

  <History>
    <CurrencyId>LRUSD</CurrencyId> 
    
    <AccountId>U6593813</AccountId>
    <From></From>  
    <Till></Till> 
    <CorrespondingAccountId>U6593813</CorrespondingAccountId> 
    <Direction></Direction> 
    <TransferId></TransferId> 
    <ReceiptId>'.$batch.'</ReceiptId> 
    <TransferType>transfer</TransferType> 
    <Source>SCI</Source> 
    <Anonymous>any</Anonymous> 
    <AmountFrom></AmountFrom> 
    <AmountTo></AmountTo> 
    
    <Pager>  
      <PageSize>1</PageSize>
      <PageNumber>1</PageNumber>
    </Pager>
  </History>
</HistoryRequest> ';

	$url="https://api.libertyreserve.com/xml/history.aspx?req=".urlencode($xml);
	$s=self::_curl($url);
	$amount=self::getStrLR($s,"<Amount>","</Amount>");
	if(!empty($amount)&&($amount>0))
	{
		return $amount;
	}
	else 
	{
		return 0;
	}


	
	}
}
?>